﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Media3D;
using System.Xml;
using System.Windows.Input;
using System.Runtime.CompilerServices;

using KELT;
using KELT.KELTObjects.LibraryObjectModel;
using KELT.Viewport;
using KELT.KELTObjects;

namespace KELT.KELTObjects.ViewportObjectModel
{
    public class ViewportObj : INotifyPropertyChanged
    {
   //     ViewPortMgr viewPortMgr;

        public SelectBox selectBox;
        public bool isSelect = false;

        public string objectIDX;
        public ViewportObj()
        {
            FrontTransform3DGroup = new Transform3DGroup();
            m_animationList = new AnimationCollection();

    //        viewPortMgr = (ViewPortMgr)Application.Current.FindResource("ViewportMgr");

            // ViewportObj 생성 시 Library Obj 바로 연결해야 함.
        }

        #region KELT_OBJ
        public KELT_OBJ LibraryObj;

        protected string m_libObjectName = null;
        public string libObjectName
        {
            get
            {
                if (m_libObjectName == null)
                {
                    if (this.LibraryObj != null)
                    {
                        m_libObjectName = this.LibraryObj.objectName;
                        return this.LibraryObj.objectName;
                    }
                    else
                    {
                        return "Untitled Object";
                    }
                }
                else
                {
                    return m_libObjectName;
                }

            }
            set
            {
                if (this.LibraryObj != null)
                {
                    this.LibraryObj.objectName = value;
                    NotifyPropertyChanged("libObjectName");
                }
            }
        }

        protected string m_objectName = null;
        public string objectName
        {
            get
            {
                if (m_objectName == null)
                {
                    return "Untitled Object";
                }
                else
                {
                    return m_objectName;
                }
            }
            set
            {
                if(LibraryObj != null)
                {
                    this.LibraryObj.objectName = value;
                    NotifyPropertyChanged("objectName");
                }
            }
        }

        public string objectID
        {
            get
            {
                return this.LibraryObj.objectID;
            }
            set
            {
                this.LibraryObj.objectID = value;
                NotifyPropertyChanged("objectID");
            }
        }

        public string objectType
        {
            get
            {
                return this.GetType().ToString();
            }
        }
        #endregion

        public string ObjectInfo;        // 이건 자동으로 만들어 줘야 맞을 듯 ?? get 함수 이용해서

        protected int indexNumber;

        //객체의 위치정보
        public Point3D point;

        //객체의 4개꼭지점 정보
        protected Point3DCollection FrontPoint3DCollection;
        protected Point3DCollection BackPoint3DCollection;

        public Viewbox frontViewBox;
        protected Viewport2DVisual3D FrontViusal;
        protected Transform3DGroup FrontTransform3DGroup;

        protected Viewbox BackViewBox;
        private Viewport2DVisual3D BackViusal;
        protected Transform3DGroup BackTransform3DGroup;

        protected Boolean isVisual = false;
        protected bool isBackPanel = false;

        private double m_startTime = 0;
        private double m_endTime = 1;

        private int m_Width = 1;
        private int m_Height = 1;

        #region Get/Set

        public double Posx
        {
            get {
                return point.X; 
            }
            set{
                point.X = value;
                NotifyPropertyChanged("Posx");
            }
        }
        public double Posy
        {
            get { return point.Y; }
            set
            {
                point.Y = value;
            }
        }
        public double Posz
        {
            get { return point.Z; }
            set
            {
                point.Z = value;
            }
        }

        public double Angle
        {
            get { return degree; }
            set { degree = value; }
        }

        public string ObjectTpye
        {
            get { return ObjectInfo; }
            set { }
        }

        public double startTime
        {
            get
            {
                return m_startTime;
            }

            set
            {
                if (value < 0)
                    value = 0;

                m_startTime = value;
                NotifyPropertyChanged("startTime");
                NotifyPropertyChanged("duration");
            }
        }
 
        public double endTime
        {
            get
            {
                return m_endTime;
            }

            set
            {

                int MainTimeBarWidth = ((ViewPortMgr)Application.Current.FindResource("ViewportMgr")).MainTimeBarWidth;
                int temp = (int)value * 100 + 500;
                if (MainTimeBarWidth < temp)
                {
                    // 마지막 객체 시간보다 5 초 더 늘림
                    ((ViewPortMgr)Application.Current.FindResource("ViewportMgr")).MainTimeBarWidth  = ((int)value) * 100 + 500;
                }
                
                m_endTime = value;

                NotifyPropertyChanged("endTime");
                NotifyPropertyChanged("duration");
            }
        }

        public double duration
        {
            get
            {
                return (endTime - startTime);
            }
        }

        virtual public int width
        {
            get
            {
                return m_Width;
            }
            set
            {
                m_Width = value;
            }
        }
        virtual public int height
        {
            get
            {
                return m_Height;
            }
            set
            {
                m_Height = value;
            }
        }
        #endregion

        public double degree = 0.0;
        /*
        private ArrayList animationList = new ArrayList();
        */
        private AnimationCollection m_animationList;
        public AnimationCollection animationList
        {
            get { return m_animationList; }
        }

        public SolidColorBrush colorBrush;
        private Boolean isMask = false;

        public ViewportObj parentObject;

        #region XML
        public void SaveObject()
        {
            //객체타입
            string objInfo = ObjectInfo;
            

            //객체 위치
            double pointX = point.X;
            double pointY = point.Y;
            double pointZ = point.Z;

            //객체 꼭지점 좌표
            int count = 4;// 모든 객체가 무조건 4개이긴 함
            double[] VertexX = new double[4];
            double[] VertexY = new double[4];
            double[] VertexZ = new double[4];

            for(int i=0; i<count; i++)
            {
                VertexX[i] = FrontPoint3DCollection[i].X;
                VertexY[i] = FrontPoint3DCollection[i].Y;
                VertexZ[i] = FrontPoint3DCollection[i].Z;
            }

            //애니메이션 시작시간,끝시간
            double SaveStartTime = this.startTime;
            double SaveEndTime = this.endTime;

            //객체각도
            double SaveDegree = this.degree;
            
            //색정보
            int R = colorBrush.Color.R;
            int G = colorBrush.Color.G;
            int B = colorBrush.Color.B;

            //마스크애니메이션 여부
            bool saveIsMask = isMask;

            if(objInfo == "TextObject")
            {
                String font = (this as TextObject).fontFamily.Source;
            }
            else if (objInfo == "PictureObject")
            {
                String imgSrc = (this as PictureObject).imgSrc;
            }
        }

        public virtual void GetObjXML(XmlWriter writer)
        {
            writer.WriteStartElement("ViewportObj");
            {
                writer.WriteAttributeString("objectType", objectType);

                if(LibraryObj != null)
                {
                    writer.WriteElementString("LibraryObject", LibraryObj.objectID);
                }

                writer.WriteElementString("objInfo", ObjectInfo);
                writer.WriteElementString("startTime", startTime.ToString());
                writer.WriteElementString("endTime", endTime.ToString());
                writer.WriteElementString("degree", degree.ToString());
                writer.WriteElementString("isMast", isMask.ToString());

                writer.WriteStartElement("colorBrush");
                {
                    writer.WriteAttributeString("A", colorBrush.Color.A.ToString());
                    writer.WriteAttributeString("R", colorBrush.Color.R.ToString());
                    writer.WriteAttributeString("G", colorBrush.Color.G.ToString());
                    writer.WriteAttributeString("B", colorBrush.Color.B.ToString());
                }
                writer.WriteEndElement();

                writer.WriteStartElement("point");
                {
                    writer.WriteAttributeString("X", point.X.ToString());
                    writer.WriteAttributeString("Y", point.Y.ToString());
                    writer.WriteAttributeString("Z", point.Z.ToString());
                }
                writer.WriteEndElement();

                // 객체 꼭지점 좌표 모두 계산해야하는 것 아닐까?
                // 정보로 가지고있는 것 맞음?
                writer.WriteStartElement("vertext");
                {
                    // 꼭지점 좌표 4개로 되어 있다고 함.
                    writer.WriteAttributeString("count", "4");

                    for(int i = 0; i < 4; i++)
                    {
                        writer.WriteStartElement(i.ToString());
                        {
                            writer.WriteAttributeString("X", FrontPoint3DCollection[i].X.ToString());
                            writer.WriteAttributeString("Y", FrontPoint3DCollection[i].Y.ToString());
                            writer.WriteAttributeString("Z", FrontPoint3DCollection[i].Z.ToString());
                        }
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();

                writer.WriteStartElement("animation");
                {
                    foreach(IAnimation animation in m_animationList)
                    {

                    }
                }
                writer.WriteEndElement();


                GetObjInfoXML(writer);
                
            }
            writer.WriteEndElement();
        }

        public virtual void GetObjInfoXML(XmlWriter writer)
        {

        }

        #endregion

        public void setObjectIDX()
        {
            objectIDX = "object"+indexNumber;
        }

        public void setLibraryObj(KELT_OBJ obj)
        {
            LibraryObj = obj;
        }
        
        private void MakeTransfor3DGroupChildren(Transform3DGroup group, bool isFront)
        {
            TranslateTransform3D translateTransform3D = new TranslateTransform3D(point.X, point.Y, point.Z);

            ScaleTransform3D scaleTransform3D = new ScaleTransform3D(1, 1, 1);
            scaleTransform3D.CenterX = point.X;
            scaleTransform3D.CenterY = point.Y;
            scaleTransform3D.CenterZ = point.Z;

            RotateTransform3D rotateTransform = new RotateTransform3D();
            rotateTransform.CenterX = point.X;
            rotateTransform.CenterY = point.Y;
            rotateTransform.CenterZ = point.Z;

            if (isFront == false)
            {
                scaleTransform3D.ScaleX = -scaleTransform3D.ScaleX;
                scaleTransform3D.ScaleY = scaleTransform3D.ScaleY;
                rotateTransform.Rotation = new AxisAngleRotation3D { Angle = 180, Axis = new Vector3D(1, 0, 0) };
            }
            else
            {
                rotateTransform.Rotation = new AxisAngleRotation3D { Angle = 0, Axis = new Vector3D(1, 0, 0) };
            }
            
            group.Children.Add(translateTransform3D);
            group.Children.Add(scaleTransform3D);
            group.Children.Add(rotateTransform);
        }

        private MeshGeometry3D MakeTriangleMesh(Point3DCollection point3DCollection)
        {

            point3DCollection.Add(new Point3D((double)-width/ 1, 1, 0));
            point3DCollection.Add(new Point3D((double)-width / 1, -1, 0));
            point3DCollection.Add(new Point3D((double)width / 1, -1, 0));
            point3DCollection.Add(new Point3D((double)width / 1, 1, 0));

            PointCollection myPointCollection = new PointCollection();
            myPointCollection.Add(new Point(0, 0));
            myPointCollection.Add(new Point(0, 1));
            myPointCollection.Add(new Point(1, 1));
            myPointCollection.Add(new Point(1, 0));


            MeshGeometry3D triangleMesh = new MeshGeometry3D();
            triangleMesh.Positions = point3DCollection;
            triangleMesh.TextureCoordinates = myPointCollection;

            triangleMesh.TriangleIndices.Add(0);
            triangleMesh.TriangleIndices.Add(1);
            triangleMesh.TriangleIndices.Add(2);
            triangleMesh.TriangleIndices.Add(0);
            triangleMesh.TriangleIndices.Add(2);
            triangleMesh.TriangleIndices.Add(3);


            return triangleMesh;
        }


        protected Viewport2DVisual3D CreateFront(Viewbox p, Transform3DGroup group)
        {
            Viewport2DVisual3D v2v3 = new Viewport2DVisual3D();
            DiffuseMaterial DiffuseMaterial = new DiffuseMaterial(Brushes.Transparent);
            Viewport2DVisual3D.SetIsVisualHostMaterial(DiffuseMaterial, true);

            FrontPoint3DCollection = new Point3DCollection();

            MakeTransfor3DGroupChildren(group, true);

            v2v3.Transform = group;
            v2v3.Material = DiffuseMaterial;
            v2v3.Geometry = MakeTriangleMesh(FrontPoint3DCollection);
            v2v3.Visual = p;

            return v2v3;
        }

        protected void CreateBack(TOOL mainContext)
        {
            if (isBackPanel == true) return;

            isBackPanel = true;

            BackViusal = new Viewport2DVisual3D();

            DiffuseMaterial DiffuseMaterial = new DiffuseMaterial(Brushes.Transparent);
            Viewport2DVisual3D.SetIsVisualHostMaterial(DiffuseMaterial, true);

            BackPoint3DCollection = new Point3DCollection();

            BackTransform3DGroup = new Transform3DGroup();
            MakeTransfor3DGroupChildren(BackTransform3DGroup, false);

            BackViusal.Transform = BackTransform3DGroup;
            BackViusal.Material = DiffuseMaterial;
            BackViusal.Geometry = MakeTriangleMesh(BackPoint3DCollection);


            BackViewBox = new Viewbox();

            BackViusal.Visual = BackViewBox;// mainCanvas;


            if (selectBox == null)
                selectBox = new SelectBox(mainContext, mainContext.Width / 2, mainContext.Height / 2, this);

            selectBox.setXYZ(mainContext, mainContext.mainViewport.RenderSize, point.X, point.Y, 0, getPoint3DCollection());

            mainContext.mainViewport.Children.Add(BackViusal);
            mainContext.RegisterName(AnimationInfo.ANIMATION_ROTATE_BACK + indexNumber, BackTransform3DGroup.Children.ElementAt(2));

        }
        public Point scaleStartPoint;

        public void setScalePoint(object sender, MouseButtonEventArgs e)
        {
            if (selectBox.selectNum < 1) return;
            switch (selectBox.selectNum)
            {
                case 5:
                    scaleStartPoint.X = (FrontPoint3DCollection[3].X + FrontPoint3DCollection[0].X) / 2;
                    scaleStartPoint.Y = (FrontPoint3DCollection[3].Y + FrontPoint3DCollection[0].Y) / 2;
                    break;
                case 6:
                    scaleStartPoint.X = (FrontPoint3DCollection[0].X + FrontPoint3DCollection[1].X) / 2;
                    scaleStartPoint.Y = (FrontPoint3DCollection[0].Y + FrontPoint3DCollection[1].Y) / 2;
                    break;
                case 7:
                    scaleStartPoint.X = (FrontPoint3DCollection[1].X + FrontPoint3DCollection[2].X) / 2;
                    scaleStartPoint.Y = (FrontPoint3DCollection[1].Y + FrontPoint3DCollection[2].Y) / 2;
                    break;
                case 8:
                    scaleStartPoint.X = (FrontPoint3DCollection[2].X + FrontPoint3DCollection[3].X) / 2;
                    scaleStartPoint.Y = (FrontPoint3DCollection[2].Y + FrontPoint3DCollection[3].Y) / 2;
                    break;
                default:
                    scaleStartPoint.X = FrontPoint3DCollection[selectBox.selectNum - 1].X;
                    scaleStartPoint.Y = FrontPoint3DCollection[selectBox.selectNum - 1].Y;
                    break;
            }

        }

        public void setMask(TOOL mainContext)
        {
            if (isMask == true) return;

            isMask = true;

            LinearGradientBrush gBrush = new LinearGradientBrush();
            
            GradientStop BlackStop = new GradientStop(colorBrush.Color, 1);
            GradientStop TransparentStop = new GradientStop(Colors.Transparent, 1);

            gBrush.GradientStops.Add(BlackStop);
            gBrush.GradientStops.Add(TransparentStop);

            mainContext.RegisterName("TransparentStop" + indexNumber, TransparentStop);
            mainContext.RegisterName("BlackStop" + indexNumber, BlackStop);
            frontViewBox.OpacityMask = gBrush;

            //frontText.Foreground = gBrush;
        }
        private void Transform3DGroupSet(Transform3DGroup transform3DGroup)
        {
            (transform3DGroup.Children.ElementAt(0) as TranslateTransform3D).OffsetX = point.X;
            (transform3DGroup.Children.ElementAt(0) as TranslateTransform3D).OffsetY = point.Y;
            (transform3DGroup.Children.ElementAt(0) as TranslateTransform3D).OffsetZ = 0;

            (transform3DGroup.Children.ElementAt(1) as ScaleTransform3D).CenterX = point.X;
            (transform3DGroup.Children.ElementAt(1) as ScaleTransform3D).CenterY = point.Y;
            (transform3DGroup.Children.ElementAt(1) as ScaleTransform3D).CenterZ = point.Z;

            (transform3DGroup.Children.ElementAt(2) as RotateTransform3D).CenterX = point.X;
            (transform3DGroup.Children.ElementAt(2) as RotateTransform3D).CenterY = point.Y;
            (transform3DGroup.Children.ElementAt(2) as RotateTransform3D).CenterZ = point.Z;
        }

        public void setXYZ(TOOL mainContext, Size size, double x, double y, double z)
        {
            double changeX = (x * 2 / size.Width - 1) * (0.4 * mainContext.cameraManager.getPoint3D().Z) + mainContext.cameraManager.getPoint3D().X + mainContext.cameraManager.getTranslateTransform().OffsetX;
            double changeY = (y * -2 / size.Height + 1) * (0.24 * mainContext.cameraManager.getPoint3D().Z) + mainContext.cameraManager.getPoint3D().Y + mainContext.cameraManager.getTranslateTransform().OffsetY;

            point.X = changeX - centerWidth;
            point.Y = changeY - centerHeight;

            Transform3DGroupSet(FrontTransform3DGroup);


            if (isBack() == true)
                Transform3DGroupSet(BackTransform3DGroup);

            selectBox.setXYZ(mainContext, mainContext.mainViewport.RenderSize, point.X, point.Y, 0, getPoint3DCollection());

        }

        private double centerWidth, centerHeight;
        public void selectObject(TOOL mainContext, Size size, Point p)
        {
            double changeX = (p.X * 2 / size.Width - 1) * (0.4 * mainContext.cameraManager.getPoint3D().Z) + mainContext.cameraManager.getPoint3D().X + mainContext.cameraManager.getTranslateTransform().OffsetX;
            double changeY = (p.Y * -2 / size.Height + 1) * (0.24 * mainContext.cameraManager.getPoint3D().Z) + mainContext.cameraManager.getPoint3D().Y + mainContext.cameraManager.getTranslateTransform().OffsetY;


            centerWidth = changeX - selectBox.CenterPoint.X;
            centerHeight = changeY - selectBox.CenterPoint.Y;

        }

        private double moveGapX = 0;
        private double moveGapY = 0;

        public void setScaleXYZ(TOOL mainContext, int num, double x, double y)
        {
            x = (x *  2 / mainContext.mainViewport.RenderSize.Width  - 1) * (0.4 * mainContext.cameraManager.getPoint3D().Z) + mainContext.cameraManager.getPoint3D().X - mainContext.cameraManager.getTranslateTransform().OffsetX;
            y = (y * -2 / mainContext.mainViewport.RenderSize.Height + 1) * (0.24 * mainContext.cameraManager.getPoint3D().Z) + mainContext.cameraManager.getPoint3D().Y - mainContext.cameraManager.getTranslateTransform().OffsetY;
            moveGapX = x - selectBox.mouseStartPoint.X;
            moveGapY = y - selectBox.mouseStartPoint.Y;

            switch (num)
            {
                case 4:
                    FrontPoint3DCollection[0] = new Point3D(FrontPoint3DCollection[0].X, scaleStartPoint.Y + moveGapY, 0);
                    BackPoint3DCollection[0] = new Point3D(BackPoint3DCollection[0].X, scaleStartPoint.Y + moveGapY, 0);

                    FrontPoint3DCollection[3] = new Point3D(FrontPoint3DCollection[3].X, scaleStartPoint.Y + moveGapY, 0);
                    BackPoint3DCollection[3] = new Point3D(BackPoint3DCollection[3].X, scaleStartPoint.Y + moveGapY, 0);
                    break;
                case 5:
                    FrontPoint3DCollection[0] = new Point3D(scaleStartPoint.X + moveGapX, FrontPoint3DCollection[0].Y, 0);
                    BackPoint3DCollection[0] = new Point3D(scaleStartPoint.X + moveGapX, BackPoint3DCollection[0].Y, 0);

                    FrontPoint3DCollection[1] = new Point3D(scaleStartPoint.X + moveGapX, FrontPoint3DCollection[1].Y, 0);
                    BackPoint3DCollection[1] = new Point3D(scaleStartPoint.X + moveGapX, BackPoint3DCollection[1].Y, 0);
                    break;
                case 6:
                    FrontPoint3DCollection[1] = new Point3D(FrontPoint3DCollection[1].X, scaleStartPoint.Y + moveGapY, 0);
                    BackPoint3DCollection[1] = new Point3D(BackPoint3DCollection[1].X, scaleStartPoint.Y + moveGapY, 0);

                    FrontPoint3DCollection[2] = new Point3D(FrontPoint3DCollection[2].X, scaleStartPoint.Y + moveGapY, 0);
                    BackPoint3DCollection[2] = new Point3D(BackPoint3DCollection[2].X, scaleStartPoint.Y + moveGapY, 0);
                    break;
                case 7:
                    FrontPoint3DCollection[2] = new Point3D(scaleStartPoint.X + moveGapX, FrontPoint3DCollection[2].Y, 0);
                    BackPoint3DCollection[2] = new Point3D(scaleStartPoint.X + moveGapX, BackPoint3DCollection[2].Y, 0);

                    FrontPoint3DCollection[3] = new Point3D(scaleStartPoint.X + moveGapX, FrontPoint3DCollection[3].Y, 0);
                    BackPoint3DCollection[3] = new Point3D(scaleStartPoint.X + moveGapX, BackPoint3DCollection[3].Y, 0);
                    break;
                default:
                    FrontPoint3DCollection[num] = new Point3D(scaleStartPoint.X + moveGapX, scaleStartPoint.Y + moveGapY, 0);
                    BackPoint3DCollection[num] = new Point3D(scaleStartPoint.X + moveGapX, scaleStartPoint.Y + moveGapY, 0);

                    break;

            }
           
            selectBox.setXYZ(mainContext, mainContext.mainViewport.RenderSize, point.X, point.Y, 0, getPoint3DCollection());

            
        }

        public void setRotate(TOOL mainContext, double degree)
        {
            this.degree = degree;
            AxisAngleRotation3D r = new AxisAngleRotation3D();
            r.Angle = degree;
            r.Axis = new Vector3D(0, 0, 1);

            (FrontTransform3DGroup.Children.ElementAt(2) as RotateTransform3D).Rotation = r;
            selectBox.setXYZ(mainContext, mainContext.mainViewport.RenderSize, point.X, point.Y, 0, getPoint3DCollection());
            //(BackTransform3DGroup.Children.ElementAt(2) as RotateTransform3D).Rotation = r;
        }



        public void setAnimationTime(Storyboard storyboard, double startTime, double endTime)
        {
            this.startTime = startTime;
            this.endTime = endTime;
        }

        public void AnimationRegist(IAnimation animation, Storyboard myStoryboard)
        {
            if (animationList.Count > 0)
            {
                IAnimation ani = animationList[animationList.Count - 1] as IAnimation;

                animation.endTime = animation.endTime + ani.endTime;
                animation.startTime = ani.endTime;
            }
            else
            {
                animation.endTime = this.startTime + animation.endTime;
                animation.startTime = this.startTime;

            }
            if (animation.endTime > endTime)
            {
                endTime = animation.endTime;
            }

            animation.SetAnimation(myStoryboard, this);

            animationList.Add(animation);
        }
        
        public void ChangeAnimation(Storyboard myStoryboard, int one, int two)
        {

            if (animationList.Count > 0)
            {
                IAnimation iA = animationList[one] as IAnimation;
                IAnimation iB = animationList[two] as IAnimation;

                double iAStart = iA.startTime;
                double iAEnd = iA.endTime;

                double iBStart = iB.startTime;
                double iBEnd = iB.endTime;

                iA.startTime = iBStart;
                iA.endTime = iBEnd;

                iB.startTime = iAStart;
                iB.endTime = iAEnd;

                iB.changeAnimation(myStoryboard);
                iA.changeAnimation(myStoryboard);

                animationList[one] = iB;
                animationList[two] = iA;
            }

        }

        public void DeleteAnimation(Storyboard myStoryboard, int num)
        {
            if (animationList.Count > 0)
            {
                IAnimation ani = animationList[num] as IAnimation;
                ani.deleteAnimation(myStoryboard);
                ani = null;

                animationList.RemoveAt(num);

            }
        }

        public void DeleteObject(TOOL Context)
        {
            for (int i = 0; i < animationList.Count; i++ )
            {
                animationList.ElementAt(i).deleteAnimation(Context.viewPortMgr.myStoryboard);
            }
            Context.mainViewport.Children.Remove(FrontViusal);
            Context.mainViewport.Children.Remove(BackViusal);
            selectBox.InvisibleSelectBox();
        }

        public void ChkObjet(TOOL Context, TimeSpan seekTime)
        {
            if (startTime <= seekTime.TotalSeconds && endTime >= seekTime.TotalSeconds)
            {
                if (isVisual == false)
                {
                    Context.mainViewport.Children.Add(FrontViusal);
                    Context.mainViewport.Children.Add(BackViusal);
                    isVisual = true;
                }
            }
            else
            {
                Context.mainViewport.Children.Remove(FrontViusal);
                Context.mainViewport.Children.Remove(BackViusal);
                isVisual = false;
            }
        }
        public Point3DCollection getPoint3DCollection()
        {
            return FrontPoint3DCollection;
        }

        public Point3D getPosition()
        {
            return point;
        }

        public double getStartTime()
        {
            return startTime;
        }

        public double getEndTime()
        {
            return endTime;
        }

        public bool isBack() 
        {
            return isBackPanel; 
        }
        
        public int getIndexNumber() 
        { 
            return indexNumber; 
        }
        public string getObjectName() 
        { 
            return objectName; 
        }

        
        public void NotifyPropertyChanged(string PropertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(PropertyName));
            }
        }
        
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
